<template>
  <div class="folder-card">
    <el-card class="folder-card__inner" shadow="never">
      <div class="folder-card__content">
        <el-row class="folder-card__title">
          <el-icon><Folder /></el-icon>
          <span>{{ folderData.fileName }}</span>
        </el-row>
        <el-row v-if="folderData.belongsNode" class="folder-card__belongs">
          所属：{{ folderData.belongsNode }}
        </el-row>
      </div>
      <el-button 
        class="select-btn" 
        :class="{ selected: isSelected }"
        circle 
        size="small" 
        @click.stop="toggleSelection"
      />
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue';
import { Folder } from '@element-plus/icons-vue';
import type { FileManage } from '../../type';

const props = defineProps<{
  folderData: FileManage;
  selectedItems: FileManage[];
}>();

const emit = defineEmits<{
  (e: 'toggleSelection', item: FileManage): void;
}>();

const isSelected = computed(() => {
  return props.selectedItems.some(item => item.id === props.folderData.id);
});

const toggleSelection = () => {
  emit('toggleSelection', props.folderData);
};
</script>

<style scoped>
.folder-card {
  min-width: 240px;
}

.folder-card__inner {
  margin-left: 10px;
  position: relative;
}

.folder-card__content {
  padding: 15px;
  min-height: 60px;
}

.folder-card__title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.folder-card__belongs {
  margin-top: 10px;
  font-size: 12px;
  color: var(--el-text-color-secondary);
}

.select-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  display: none;
  padding: 0;
  width: 16px;
  height: 16px;
  border: 1px solid var(--el-border-color);
  background-color: transparent;
}

.folder-card:hover .select-btn {
  display: block;
}

.select-btn.selected {
  display: block;
  background-color: var(--el-color-primary);
  border: none;
}
</style> 